define([
    '../common/ReminderPanel',
    './EllipsePlotting',
    './PointPlotting',
    './PolygonPlotting',
    './PolylinePlotting',
    './RectanglePlotting'
  ], function (
  ReminderPanel,
  EllipsePlotting,
  PointPlotting,
  PolygonPlotting,
  PolylinePlotting,
  RectanglePlotting
  ) {
    let reminder = new ReminderPanel();                                       //提醒框
    let handler                                                               //屏幕监听事件
    let plotEntities = new Cesium.CustomDataSource("plotEntities");           //管理一组实体

    viewer.dataSources.add(plotEntities);
    /*
      标绘管理入口
     */
    return function () {

      //屏幕监听事件销毁与初始化
      $('#plotModule').click(function () {
        viewer.scene.screenSpaceCameraController.enableRotate = true;
        destroyAllPlot()
        destroyAllMeasure()
        handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
      });

      $('#pointPlot').click(function () {
        reminder.show('正在绘制点')
        new PointPlotting(viewer, handler, plotEntities)
      })

      $('#polylinePlot').click(function () {
        reminder.show('正在绘制线')
        new PolylinePlotting(viewer, handler, plotEntities)
      })

      $('#polygonPlot').click(function () {
        reminder.show('正在绘制面')
        new PolygonPlotting(viewer, handler, plotEntities)
      })

      $('#ellipsePlot').click(function () {
        reminder.show('正在绘制椭圆')
        new EllipsePlotting(viewer, handler, plotEntities)
      })

      $('#rectanglePlot').click(function () {
        reminder.show('正在绘制矩形')
        new RectanglePlotting(viewer, handler, plotEntities)
      })

      $('#clearPlot').click(function () {
        reminder.show('清除标绘')
        clearPlot()
      })

      //清除标绘
      window.clearPlot = function () {
        plotEntities.entities.removeAll()
      }

      //销毁标绘事件监听
      window.destroyAllPlot = function () {
        if (handler !== undefined) {
          if (!handler.isDestroyed()) {
            handler.destroy()
            console.log('destroy')
          }
        }
      }
    }
  }
)